import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
import { UserInfosStates,UserInfosState } from './interface';
import { Session } from '/@/utils/storage';

/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 */
export const useUserInfo = defineStore('userInfo', {
	state: (): UserInfosStates => ({
		userInfos: {
			'userName':"",
	"photo":"",
	"time":"",
	"roles":[],
	"authBtnList": []
		},
	}),
	actions: {
		async setUserInfos(userInfos:UserInfosState) {
			// 存储用户信息到浏览器缓存
			Session.set('userInfo', userInfos);

			if (Session.get('userInfo')) {
				this.userInfos = Session.get('userInfo');
			} else {
				this.userInfos = userInfos;
			}
		},
	},
});
